/**
* web file
* 
*/

String root_html(IPAddress myIP, float pwr) {
    String htmlStr;
    htmlStr += F("<!DOCTYPE html>");
    htmlStr += F("<html>");
    htmlStr += F("<head>");
    htmlStr += F("<meta charset='utf-8'>");
    htmlStr += F("<title>PriceTag</title>");
    htmlStr += F("<link rel='icon' href='data:;base64,='>");
    htmlStr += F("<link rel='stylesheet' href='styles.css'>");
    htmlStr += F("<script src='scriptA.js'></script>");
    htmlStr += F("<script src='scriptB.js'></script>");
    htmlStr += F("<script src='scriptC.js'></script>");
    htmlStr += F("<script src='scriptD.js'></script>");
    htmlStr += F("</head>");
    htmlStr += F("<body>");
    htmlStr += F("<div class='header_back'>");
    htmlStr += F("<div class='header_face'>Power:&nbsp;");
    htmlStr += String(pwr);
    htmlStr += F("v</div>");
    htmlStr += F("</div>");
    htmlStr += F("<div class='content_back'>");
    htmlStr += F("<div class='content_face'>");
    htmlStr += F("<table style='width:100%; height:100%' border='0' cellspacing='0'>");
    htmlStr += F("<tr>");
    htmlStr += F("<td class='menu_bar' rowspan='2'>");
    htmlStr += F("<div id='BT'></div>");
    htmlStr += F("<table>");
    htmlStr += F("<tr>");
    htmlStr += F("<td class='comment' colspan='4'><br>Device IP:</td>");
    htmlStr += F("</tr>");
    htmlStr += F("<tr>");
    htmlStr += F("<td colspan=\"4\"><input id=\"ip_addr\" style=\"width:100%;text-align:center\" type=\"text\" value=\"");
    htmlStr += String(myIP[0],DEC)+'.'+String(myIP[1],DEC)+'.'+String(myIP[2],DEC)+'.'+String(myIP[3],DEC);
    htmlStr += F("\"></td>");
    htmlStr += F("</tr>");
    htmlStr += F("<tr><td class='comment' colspan='4'><br>Bounds:</td></tr>");
    htmlStr += F("<tr id='XY'></tr>");
    htmlStr += F("<tr id='WH'></tr>");
    htmlStr += F("</table>");
    htmlStr += F("<div id='RB'></div>");
    htmlStr += F("</td>");
    htmlStr += F("<td class='content_body'>");
    htmlStr += F("<span class='title'>Original image</span><br>");
    htmlStr += F("<canvas id='source' class='hidden_input'></canvas>");
    htmlStr += F("<div id='srcBox'>");
    htmlStr += F("<div class='imgBox'>");
    htmlStr += F("<div class='mesBox'>Drop image here...</div>");
    htmlStr += F("</div>");
    htmlStr += F("</div>");
    htmlStr += F("</td>");
    htmlStr += F("</tr>");
    htmlStr += F("<tr>");
    htmlStr += F("<td id='dstBox' class='content_body'>");
    htmlStr += F("</td>");
    htmlStr += F("</tr>");
    htmlStr += F("</table>");
    htmlStr += F("</div>");
    htmlStr += F("</div>");
    htmlStr += F("<div class='footer_back'>");
    htmlStr += F("<div class='footer_face' id='logTag'>");
    htmlStr += F("</div>");
    htmlStr += F("</div>");
    htmlStr += F("</body>");
    htmlStr += F("</html>");

    return htmlStr;
}

String root_css() {
    String jsStr;
    jsStr += F(".menu_button {");
    jsStr += F("width: 100%;");
    jsStr += F("height: 50px;");
    jsStr += F("border-radius: 4px;");
    jsStr += F("text-align: center;");
    jsStr += F("cursor: pointer;");
    jsStr += F("display: block;");
    jsStr += F("margin-bottom:5px;");
    jsStr += F("font: 14px/50px Tahoma;");
    jsStr += F("transition: all 0.18s ease-in-out;");
    jsStr += F("border: 1px solid #4FD666;");
    jsStr += F("background: linear-gradient(to top right, #3EC97A, #69EA49 20%, rgba(255, 255, 255, 0) 80%, rgba(255, 255, 255, 0)) top right/500% 500%;");
    jsStr += F("color: green;");
    jsStr += F("}");
    jsStr += F(".menu_button:hover {");
    jsStr += F("color: white;");
    jsStr += F("background-position: bottom left;");
    jsStr += F("}");
    jsStr += F(".hidden_input {");
    jsStr += F("width: 0.1px;");
    jsStr += F("height: 0.1px;");
    jsStr += F("opacity: 0;");
    jsStr += F("overflow: hidden;");
    jsStr += F("position: absolute;");
    jsStr += F("z-index: -1;");
    jsStr += F("}");
    jsStr += F(".imgBox");
    jsStr += F("{");
    jsStr += F("border: 2px dashed green;");
    jsStr += F("border-radius: 8px;");
    jsStr += F("background: lightyellow;");
    jsStr += F("background-repeat: no-repeat;");
    jsStr += F("text-align: center;");
    jsStr += F("margin-top:10px;");
    jsStr += F("}");
    jsStr += F(".mesBox {");
    jsStr += F("margin: 100px 70px;");
    jsStr += F("color: green;");
    jsStr += F("font-size: 25px;");
    jsStr += F("font-family: Verdana, Arial, sans-serif;");
    jsStr += F("}");
    jsStr += F(".header_back");
    jsStr += F("{");
    jsStr += F("width:100%;");
    jsStr += F("height:100px;");
    jsStr += F("background:#EEEEEE;");
    jsStr += F("}");
    jsStr += F(".content_back");
    jsStr += F("{");
    jsStr += F("width:100%;");
    jsStr += F("background:#EEEEEE;");
    jsStr += F("}");
    jsStr += F(".footer_back");
    jsStr += F("{");
    jsStr += F("width:100%;");
    jsStr += F("height:100px;");
    jsStr += F("background:#EEEEEE;");
    jsStr += F("}");
    jsStr += F(".header_face");
    jsStr += F("{");
    jsStr += F("width:1024px;");
    jsStr += F("height:100px;");
    jsStr += F("margin:0 auto;");
    jsStr += F("background:#CCFFCC;");
    jsStr += F("text-align:center;");
    jsStr += F("line-height:100px;");
    jsStr += F("}");
    jsStr += F(".content_face");
    jsStr += F("{");
    jsStr += F("width:1024px;");
    jsStr += F("height:100%;");
    jsStr += F("margin:0 auto;");
    jsStr += F("background:#FFFFFF;");
    jsStr += F("}");
    jsStr += F(".footer_face");
    jsStr += F("{");
    jsStr += F("width:1024px;");
    jsStr += F("height:100%;");
    jsStr += F("margin:0 auto;");
    jsStr += F("background:#CCFFCC;");
    jsStr += F("}");
    jsStr += F(".menu_bar");
    jsStr += F("{");
    jsStr += F("border-right:1px solid #4FD666;");
    jsStr += F("background:#EEFFEE;");
    jsStr += F("vertical-align:top;");
    jsStr += F("padding:15px;");
    jsStr += F("width:200px;");
    jsStr += F("height:100%");
    jsStr += F("}");
    jsStr += F(".content_body");
    jsStr += F("{");
    jsStr += F("vertical-align:top;");
    jsStr += F("text-align:center;");
    jsStr += F("height:100%;");
    jsStr += F("padding:30px;");
    jsStr += F("padding-left:15px;");
    jsStr += F("}");
    jsStr += F(".title");
    jsStr += F("{");
    jsStr += F("color:green;");
    jsStr += F("font-size:32px;");
    jsStr += F("font-family: arial;");
    jsStr += F("}");
    jsStr += F(".comment");
    jsStr += F("{");
    jsStr += F("width:100%;");
    jsStr += F("color:green;");
    jsStr += F("font-size:16px;");
    jsStr += F("font-style:italic;");
    jsStr += F("font-family: arial;");
    jsStr += F("text-align:center;");
    jsStr += F("}");
    jsStr += F(".nud");
    jsStr += F("{");
    jsStr += F("width:70px;");
    jsStr += F("}");
    return jsStr;
}

String root_script_a() {
    String jsStr;
    jsStr += F("var srcBox,srcImg,dstImg;");
    jsStr += F("var epdArr,epdInd,palArr;");
    jsStr += F("var curPal;");
    jsStr += F("function getElm(n){return document.getElementById(n);}");
    jsStr += F("function setInn(n,i){ document.getElementById(n).innerHTML=i;}");
    jsStr += F("function processFiles(files){");
    jsStr += F("var file=files[0];");
    jsStr += F("var reader=new FileReader();");
    jsStr += F("srcImg=new Image();");
    jsStr += F("reader.onload=function(e){");
    jsStr += F("setInn('srcBox','<img id=\"imgView\" class=\"sourceImage\">');");
    jsStr += F("var img=getElm('imgView');");
    jsStr += F("img.src=e.target.result;");
    jsStr += F("srcImg.src=e.target.result;");
    jsStr += F("};");
    jsStr += F("reader.readAsDataURL(file);");
    jsStr += F("}");
    jsStr += F("function drop(e){");
    jsStr += F("e.stopPropagation();");
    jsStr += F("e.preventDefault();");
    jsStr += F("var files=e.dataTransfer.files;");
    jsStr += F("processFiles(files);");
    jsStr += F("}");
    jsStr += F("function ignoreDrag(e){");
    jsStr += F("e.stopPropagation();");
    jsStr += F("e.preventDefault();");
    jsStr += F("}");
    jsStr += F("function getNud(nm,vl){");
    jsStr += F("return '<td class=\"comment\">'+nm+':</td>'+");
    jsStr += F("'<td><input id=\"nud_'+nm+'\" class=\"nud\"type=\"number\" value=\"'+vl+'\"/></td>';");
    jsStr += F("}");
    jsStr += F("function Btn(nm,tx,fn){");
    jsStr += F("return '<div><label class=\"menu_button\" for=\"_'+nm+'\">'+tx+'</label>'+");
    jsStr += F("'<input class=\"hidden_input\" id=\"_'+nm+'\" type=\"'+");
    jsStr += F("(nm==0?'file\" onchange=\"':'button\" onclick=\"')+fn+'\"/></div>';");
    jsStr += F("}");
    jsStr += F("function RB(vl,tx){");
    jsStr += F("return '<input type=\"radio\" name=\"kind\" value=\"m'+vl+");
    jsStr += F("'\" onclick=\"rbClick('+vl+');\"'+(vl==0?'checked=\"true\"':'')+'/>'+tx;");
    jsStr += F("}");
    jsStr += F("window.onload = function(){");
    jsStr += F("srcBox = getElm('srcBox');");
    jsStr += F("srcBox.ondragenter=ignoreDrag;");
    jsStr += F("srcBox.ondragover=ignoreDrag;");
    jsStr += F("srcBox.ondrop=drop;");
    jsStr += F("srcImg=0;");
    jsStr += F("epdInd=0;");
    jsStr += F("palArr=[[[0,0,0],[255,255,255]],");
    jsStr += F("[[0,0,0],[255,255,255],[127,0,0]],");
    jsStr += F("[[0,0,0],[255,255,255],[127,127,127]],");
    jsStr += F("[[0,0,0],[255,255,255],[127,127,127],[127,0,0]],");
    jsStr += F("[[0,0,0],[255,255,255]],");
    jsStr += F("[[0,0,0],[255,255,255],[220,180,0]],");
    jsStr += F("[[0,0,0]],");
    jsStr += F("[[0,0,0],[255,255,255],[0,255,0],[0,0,255],[255,0,0],[255,255,0],[255,128,0]]];"); // 5.65f 7-color E-Paper
    jsStr += F("epdArr=[[200,200,0],[200,200,3],[152,152,5],");
    jsStr += F("[122,250,0],[104,212,1],[104,212,5],[104,212,0],");
    jsStr += F("[176,264,0],[176,264,1],");
    jsStr += F("[128,296,0],[128,296,1],[128,296,5],[128,296,0],");
    jsStr += F("[400,300,0],[400,300,1],[400,300,5],");
    jsStr += F("[600,448,0],[600,448,1],[600,448,5],");
    jsStr += F("[640,384,0],[640,384,1],[640,384,5],");
    jsStr += F("[800,480,0],[800,480,1],[880,528,1],");
    jsStr += F("[600,448,7],[880,528,0],[280,480,0],");
    jsStr += F("[152,296,0],[648,480,1],[128,296,1],");
    jsStr += F("[200,200,1],[104,214,1],[128,296,0],");
    jsStr += F("[400,300,1],[152,296,1],[648,480,0],");
    jsStr += F("[640,400,7],[176,264,1],[122,250,0],");
    jsStr += F("[122,250,1],[240,360,0],[176,264,0],");
    jsStr += F("[122,250,0],[400,300,0],[960,680,0],");
    jsStr += F("[800,480,0],[128,296,1],[960,680,1]];");
    jsStr += F("setInn('BT',");
    jsStr += F("Btn(0,'Select image file','processFiles(this.files);')+");
    jsStr += F("Btn(1,'Level: mono','procImg(true,false);')+");
    jsStr += F("Btn(2,'Level: color','procImg(true,true);')+");
    jsStr += F("Btn(3,'Dithering: mono','procImg(false,false);')+");
    jsStr += F("Btn(4,'Dithering: color','procImg(false,true);')+");
    jsStr += F("Btn(5,'Upload image','uploadImage();'));");
    jsStr += F("setInn('XY',getNud('x','0')+getNud('y','0'));");
    jsStr += F("setInn('WH',getNud('w','200')+getNud('h','200'));");
    jsStr += F("setInn('RB',RB(0,'1.54&ensp;')+RB(1,'1.54b')+RB(2,'1.54c&ensp;<br>')+");
    jsStr += F("RB(3,'2.13&ensp;')+RB(4,'2.13b')+RB(5,'2.13c<br>')+");
    jsStr += F("RB(6,'2.13d')+RB(7,'2.7&ensp;&ensp;')+RB(8,'2.7b&ensp;<br>')+");
    jsStr += F("RB(9,'2.9&ensp;&ensp;')+RB(10,'2.9b&ensp;')+RB(11,'2.9c&ensp;<br>')+");
    jsStr += F("RB(12,'2.9d&ensp;')+RB(13,'4.2&ensp;&ensp;')+RB(14,'4.2b&ensp;<br>')+");
    jsStr += F("RB(15,'4.2c&ensp;')+RB(16,'5.83&ensp;')+RB(17,'5.83b<br>')+");
    jsStr += F("RB(18,'5.83c&ensp;')+RB(19,'7.5&ensp;&ensp;')+RB(20,'7.5b&ensp;<br>')+");
    jsStr += F("RB(21,'7.5c')+RB(22,'7.5 V2')+RB(23,'7.5b V2<br>')+");
    jsStr += F("RB(24,'7.5b HD&ensp;')+RB(25,'5.65f<br>')+");
    jsStr += F("RB(26,'7.5 HD&ensp;')+RB(27,'3.7&ensp;')+RB(28,'2.66<br>')+");
    jsStr += F("RB(29,'5.83b V2&ensp;')+RB(30,'2.9b V3<br>')+");
    jsStr += F("RB(31,'1.54b V2&ensp;')+RB(32,'2.13b V3<br>')+");
    jsStr += F("RB(33,'2.9 V2&ensp;')+RB(34,'4.2b V2<br>')+");
    jsStr += F("RB(35,'2.66b&ensp;')+RB(36,'5.83 V2<br>')+");
    jsStr += F("RB(37,'4.01 f&ensp;')+RB(38,'2.7b V2<br>')+");
    jsStr += F("RB(39,'2.13 V3&ensp;')+RB(40,'2.13 B V4<br>')+");
    jsStr += F("RB(41,'3.52&ensp;')+RB(42,'2.7 V2<br>')+");
    jsStr += F("RB(43,'2.13 V4&ensp;')+RB(44,'4.2 V2<br>')+");
    jsStr += F("RB(45,'13.3k&ensp;')+RB(46,'4.26<br>')+");
    jsStr += F("RB(47,'2.9bV4&ensp;')+RB(48,'13.3b<br>'));");
    jsStr += F("};");
    jsStr += F("function rbClick(index){");
    jsStr += F("getElm('nud_w').value=""+epdArr[index][0];");
    jsStr += F("getElm('nud_h').value=""+epdArr[index][1];");
    jsStr += F("epdInd=index;");
    jsStr += F("}");

    return jsStr;
}

String root_script_b() {
    String jsStr;
    jsStr += F("var source;");
    jsStr += F("var dX, dY, dW, dH, sW, sH;");
    jsStr += F("function getVal(p, i){");
    jsStr += F("if((p.data[i]==0x00) && (p.data[i+1]==0x00))return 0;");
    jsStr += F("if((p.data[i]==0xFF) && (p.data[i+1]==0xFF))return 1;");
    jsStr += F("if((p.data[i]==0x7F) && (p.data[i+1]==0x7F))return 2;");
    jsStr += F("return 3;");
    jsStr += F("}");
    jsStr += F("function getVal_7color(p, i) {"); //for 5.65f E-Paper
    jsStr += F("if((p.data[i]==0x00) && (p.data[i+1]==0x00) && (p.data[i+2]==0x00))return 0;");
    jsStr += F("if((p.data[i]==0xFF) && (p.data[i+1]==0xFF) && (p.data[i+2]==0xFF))return 1;");
    jsStr += F("if((p.data[i]==0x00) && (p.data[i+1]==0xFF) && (p.data[i+2]==0x00))return 2;");
    jsStr += F("if((p.data[i]==0x00) && (p.data[i+1]==0x00) && (p.data[i+2]==0xFF))return 3;");
    jsStr += F("if((p.data[i]==0xFF) && (p.data[i+1]==0x00) && (p.data[i+2]==0x00))return 4;");
    jsStr += F("if((p.data[i]==0xFF) && (p.data[i+1]==0xFF) && (p.data[i+2]==0x00))return 5;");
    jsStr += F("if((p.data[i]==0xFF) && (p.data[i+1]==0x80) && (p.data[i+2]==0x00))return 6;");
    jsStr += F("return 7;");
    jsStr += F("}");
    jsStr += F("function setVal(p,i,c){");
    jsStr += F("p.data[i]=curPal[c][0];");
    jsStr += F("p.data[i+1]=curPal[c][1];");
    jsStr += F("p.data[i+2]=curPal[c][2];");
    jsStr += F("p.data[i+3]=255;");
    jsStr += F("}");
    jsStr += F("function addVal(c,r,g,b,k){");
    jsStr += F("return[c[0]+(r*k)/32,c[1]+(g*k)/32,c[2]+(b*k)/32];");
    jsStr += F("}");
    jsStr += F("function getErr(r,g,b,stdCol){");
    jsStr += F("r-=stdCol[0];");
    jsStr += F("g-=stdCol[1];");
    jsStr += F("b-=stdCol[2];");
    jsStr += F("return r*r + g*g + b*b;");
    jsStr += F("}");
    jsStr += F("function getNear(r,g,b){");
    jsStr += F("var ind=0;");
    jsStr += F("var err=getErr(r,g,b,curPal[0]);");
    jsStr += F("for (var i=1;i<curPal.length;i++)");
    jsStr += F("{");
    jsStr += F("var cur=getErr(r,g,b,curPal[i]);");
    jsStr += F("if (cur<err){err=cur;ind=i;}");
    jsStr += F("}");
    jsStr += F("return ind;");
    jsStr += F("}");
    return jsStr;
}

String root_script_c() {
    String jsStr;
    jsStr += F("function procImg(isLvl,isRed){");
    jsStr += F("if (document.getElementsByClassName('sourceImage').length == 0){");
    jsStr += F("alert('First select image');");
    jsStr += F("return;");
    jsStr += F("}");
    jsStr += F("var palInd=epdArr[epdInd][2];");
    jsStr += F("if (isRed&&((palInd&1)==0)){");
    jsStr += F("alert('This white-black display');");
    jsStr += F("return;");
    jsStr += F("}");
    jsStr += F("if (!isRed)palInd=palInd&0xFE;");
    jsStr += F("curPal=palArr[palInd];");
    jsStr += F("getElm('dstBox').innerHTML=");
    jsStr += F("'<span class=\"title\">Processed image</span><br><canvas id=\"canvas\"></canvas>';" );
    jsStr += F("var canvas=getElm('canvas');");
    jsStr += F("sW=srcImg.width;");
    jsStr += F("sH=srcImg.height;");
    jsStr += F("source=getElm('source');");
    jsStr += F("source.width=sW;");
    jsStr += F("source.height=sH;");
    jsStr += F("source.getContext('2d').drawImage(srcImg,0,0,sW,sH);");
    jsStr += F("dX=parseInt(getElm('nud_x').value);");
    jsStr += F("dY=parseInt(getElm('nud_y').value);");
    jsStr += F("dW=parseInt(getElm('nud_w').value);");
    jsStr += F("dH=parseInt(getElm('nud_h').value);");
    jsStr += F("if((dW<3)||(dH<3)){");
    jsStr += F("alert('Image is too small');");
    jsStr += F("return;");
    jsStr += F("}");
    jsStr += F("canvas.width=dW;");
    jsStr += F("canvas.height=dH;");
    jsStr += F("var index=0;");
    jsStr += F("var pSrc=source.getContext('2d').getImageData(0,0,sW,sH);");
    jsStr += F("var pDst=canvas.getContext('2d').getImageData(0,0,dW,dH);");
    jsStr += F("if(isLvl){");
    jsStr += F("for (var j=0;j<dH;j++){");
    jsStr += F("var y=dY+j;");
    jsStr += F("if ((y<0)||(y>=sH)){");
    jsStr += F("for (var i=0;i<dW;i++,index+=4) setVal(pDst,index,(i+j)%2==0?1:0);");
    jsStr += F("continue;");
    jsStr += F("}");
    jsStr += F("for (var i=0;i<dW;i++){");
    jsStr += F("var x=dX+i;");
    jsStr += F("if ((x<0)||(x>=sW)){");
    jsStr += F("setVal(pDst,index,(i+j)%2==0?1:0);");
    jsStr += F("index+=4;");
    jsStr += F("continue;");
    jsStr += F("}");
    jsStr += F("var pos=(y*sW+x)*4;");
    jsStr += F("setVal(pDst,index,getNear(pSrc.data[pos],pSrc.data[pos+1],pSrc.data[pos+2]));");
    jsStr += F("index+=4;");
    jsStr += F("}");
    jsStr += F("}");
    jsStr += F("}else{");
    jsStr += F("var aInd=0;");
    jsStr += F("var bInd=1;");
    jsStr += F("var errArr=new Array(2);");
    jsStr += F("errArr[0]=new Array(dW);");
    jsStr += F("errArr[1]=new Array(dW);");
    jsStr += F("for (var i=0;i<dW;i++)");
    jsStr += F("errArr[bInd][i]=[0,0,0];");
    jsStr += F("for (var j=0;j<dH;j++){");
    jsStr += F("var y=dY+j;");
    jsStr += F("if ((y<0)||(y>=sH)){");
    jsStr += F("for (var i=0;i<dW;i++,index+=4)setVal(pDst,index,(i+j)%2==0?1:0);");
    jsStr += F("continue;");
    jsStr += F("}");
    jsStr += F("aInd=((bInd=aInd)+1)&1;");
    jsStr += F("for (var i=0;i<dW;i++)errArr[bInd][i]=[0,0,0];");
    jsStr += F("for (var i=0;i<dW;i++){");
    jsStr += F("var x=dX+i;");
    jsStr += F("if ((x<0)||(x>=sW)){");
    jsStr += F("setVal(pDst,index,(i+j)%2==0?1:0);");
    jsStr += F("index+=4;");
    jsStr += F("continue;");
    jsStr += F("}");
    jsStr += F("var pos=(y*sW+x)*4;");
    jsStr += F("var old=errArr[aInd][i];");
    jsStr += F("var r=pSrc.data[pos  ]+old[0];");
    jsStr += F("var g=pSrc.data[pos+1]+old[1];");
    jsStr += F("var b=pSrc.data[pos+2]+old[2];");
    jsStr += F("var colVal = curPal[getNear(r,g,b)];");
    jsStr += F("pDst.data[index++]=colVal[0];");
    jsStr += F("pDst.data[index++]=colVal[1];");
    jsStr += F("pDst.data[index++]=colVal[2];");
    jsStr += F("pDst.data[index++]=255;");
    jsStr += F("r=(r-colVal[0]);");
    jsStr += F("g=(g-colVal[1]);");
    jsStr += F("b=(b-colVal[2]);");
    jsStr += F("if (i==0){");
    jsStr += F("errArr[bInd][i  ]=addVal(errArr[bInd][i  ],r,g,b,7.0);");
    jsStr += F("errArr[bInd][i+1]=addVal(errArr[bInd][i+1],r,g,b,2.0);");
    jsStr += F("errArr[aInd][i+1]=addVal(errArr[aInd][i+1],r,g,b,7.0);");
    jsStr += F("}else if (i==dW-1){");
    jsStr += F("errArr[bInd][i-1]=addVal(errArr[bInd][i-1],r,g,b,7.0);");
    jsStr += F("errArr[bInd][i  ]=addVal(errArr[bInd][i  ],r,g,b,9.0);");
    jsStr += F("}else{");
    jsStr += F("errArr[bInd][i-1]=addVal(errArr[bInd][i-1],r,g,b,3.0);");
    jsStr += F("errArr[bInd][i  ]=addVal(errArr[bInd][i  ],r,g,b,5.0);");
    jsStr += F("errArr[bInd][i+1]=addVal(errArr[bInd][i+1],r,g,b,1.0);");
    jsStr += F("errArr[aInd][i+1]=addVal(errArr[aInd][i+1],r,g,b,7.0);");
    jsStr += F("}");
    jsStr += F("}");
    jsStr += F("}");
    jsStr += F("}");
    jsStr += F("canvas.getContext('2d').putImageData(pDst,0,0);");
    jsStr += F("}");
    return jsStr;
}

String root_script_d() {
    String jsStr;
    jsStr += F("var pxInd, stInd;");
    jsStr += F("var dispW, dispH;");
    jsStr += F("var xhReq, dispX;");
    jsStr += F("var rqPrf, rqMsg;");
    jsStr += F("function byteToStr(v) {");
    jsStr += F("return String.fromCharCode((v & 0xF) + 97, ((v >> 4) & 0xF) + 97);");
    jsStr += F("}");
    jsStr += F("function wordToStr(v) {");
    jsStr += F("return byteToStr(v & 0xFF) + byteToStr((v >> 8) & 0xFF);");
    jsStr += F("}");
    jsStr += F("function u_send(cmd, next, data) {");
    jsStr += F("let param = '';");
    jsStr += F("if (data) {");
    jsStr += F("let strData = [];");
    jsStr += F("Object.keys(data).forEach(k => strData.push(`${k}=${window.decodeURIComponent(data[k])}`));");
    jsStr += F("param = '?' + strData.join('&');");
    jsStr += F("}");
    jsStr += F("xhReq.open('POST', rqPrf + cmd + param, true);");
    jsStr += F("xhReq.send('');");
    jsStr += F("if (next)");
    jsStr += F("stInd++;");
    jsStr += F("return 0;");
    jsStr += F("}");
    jsStr += F("function u_next() {");
    jsStr += F("lnInd = 0;");
    jsStr += F("pxInd = 0;");
    jsStr += F("u_send('NEXT', true);");
    jsStr += F("}");
    jsStr += F("function u_done() {");
    jsStr += F("setInn('logTag', 'Complete!');");
    jsStr += F("return u_send('SHOW', true);");
    jsStr += F("}");
    jsStr += F("function u_show(a, k1, k2) {");
    jsStr += F("var x = '' + (k1 + k2 * pxInd / a.length);");
    jsStr += F("if (x.length > 5)");
    jsStr += F("x = x.substring(0, 5);");
    jsStr += F("setInn('logTag', 'Progress: ' + x + '%');");
    jsStr += F("return u_send('DATA', pxInd >= a.length, { d: rqMsg + wordToStr(rqMsg.length) + 'LOAD' });");
    jsStr += F("}");
    jsStr += F("function u_data(a, c, k1, k2) {");
    jsStr += F("rqMsg = '';");
    jsStr += F("if (c == -1) {");
    jsStr += F("while ((pxInd < a.length) && (rqMsg.length < 1000)) {");
    jsStr += F("var v = 0;");
    jsStr += F("for (var i = 0; i < 16; i += 2)");
    jsStr += F("if (pxInd < a.length)");
    jsStr += F("v |= (a[pxInd++] << i);");
    jsStr += F("rqMsg += wordToStr(v);");
    jsStr += F("}");
    jsStr += F("} else if (c == -2) {");
    jsStr += F("while ((pxInd < a.length) && (rqMsg.length < 1000)) {");
    jsStr += F("var v = 0;");
    jsStr += F("for (var i = 0; i < 16; i += 4)");
    jsStr += F("if (pxInd < a.length)");
    jsStr += F("v |= (a[pxInd++] << i);");
    jsStr += F("rqMsg += wordToStr(v);");
    jsStr += F("}");
    jsStr += F("} else {");
    jsStr += F("while ((pxInd < a.length) && (rqMsg.length < 1000)) {");
    jsStr += F("var v = 0;");
    jsStr += F("for (var i = 0; i < 8; i++)");
    jsStr += F("if ((pxInd < a.length) && (a[pxInd++] != c))");
    jsStr += F("v |= (128 >> i);");
    jsStr += F("rqMsg += byteToStr(v);");
    jsStr += F("}");
    jsStr += F("}");
    jsStr += F("return u_show(a, k1, k2);");
    jsStr += F("}");
    jsStr += F("function u_line(a, c, k1, k2) {");
    jsStr += F("var x;");
    jsStr += F("rqMsg = '';");
    jsStr += F("while (rqMsg.length < 1000) {");
    jsStr += F("x = 0;");
    jsStr += F("while (x < 122) {");
    jsStr += F("var v = 0;");
    jsStr += F("for (var i = 0; (i < 8) && (x < 122); i++,");
    jsStr += F("x++)");
    jsStr += F("if (a[pxInd++] != c)");
    jsStr += F("v |= (128 >> i);");
    jsStr += F("rqMsg += byteToStr(v);");
    jsStr += F("}");
    jsStr += F("}");
    jsStr += F("return u_show(a, k1, k2);");
    jsStr += F("}");
    jsStr += F("function uploadImage() {");
    jsStr += F("var c = getElm('canvas');");
    jsStr += F("var w = dispW = c.width;");
    jsStr += F("var h = dispH = c.height;");
    jsStr += F("var p = c.getContext('2d').getImageData(0, 0, w, h);");
    jsStr += F("var a = new Array(w * h);");
    jsStr += F("var i = 0;");
    jsStr += F("for (var y = 0; y < h; y++)");
    jsStr += F("for (var x = 0; x < w; x++,");
    jsStr += F("i++) {");
    jsStr += F("if (epdInd == 25 || epdInd == 37)");
    jsStr += F("a[i] = getVal_7color(p, i << 2);");
    jsStr += F("else a[i] = getVal(p, i << 2);");
    jsStr += F("}");
    jsStr += F("dispX = 0;");
    jsStr += F("pxInd = 0;");
    jsStr += F("stInd = 0;");
    jsStr += F("xhReq = new XMLHttpRequest();");
    jsStr += F("rqPrf = 'http://' + getElm('ip_addr').value + '/';");
    jsStr += F("if ((epdInd == 3) || (epdInd == 39) || (epdInd == 43)) {");
    jsStr += F("xhReq.onload = xhReq.onerror = function() {");
    jsStr += F("if (stInd == 0)");
    jsStr += F("return u_line(a, 0, 0, 100);");
    jsStr += F("if (stInd == 1)");
    jsStr += F("return u_done();");
    jsStr += F("};");
    jsStr += F("if (epdInd > 25)");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + -26 + 65) });");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + 97) });");
    jsStr += F("}");
    jsStr += F("if ((epdInd == 40)) {");
    jsStr += F("xhReq.onload = xhReq.onerror = function() {");
    jsStr += F("if (stInd == 0)");
    jsStr += F("return u_line(a, 0, 0, 50);");
    jsStr += F("if (stInd == 1)");
    jsStr += F("return u_next();");
    jsStr += F("if (stInd == 2)");
    jsStr += F("return u_line(a, 3, 50, 50);");
    jsStr += F("if (stInd == 3)");
    jsStr += F("return u_done();");
    jsStr += F("};");
    jsStr += F("if (epdInd > 25)");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + -26 + 65) });");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + 97) });");
    jsStr += F("}");
    jsStr += F("if ((epdInd == 0) || (epdInd == 3) || (epdInd == 6) || (epdInd == 7) || (epdInd == 9) || (epdInd == 12) || (epdInd == 16) || (epdInd == 19) || (epdInd == 22) || (epdInd == 26) || (epdInd == 27) || (epdInd == 28)) {");
    jsStr += F("xhReq.onload = xhReq.onerror = function() {");
    jsStr += F("if (stInd == 0)");
    jsStr += F("return u_data(a, 0, 0, 100);");
    jsStr += F("if (stInd == 1)");
    jsStr += F("return u_done();");
    jsStr += F("};");
    jsStr += F("if (epdInd > 25)");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + -26 + 65) });");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + 97) });");
    jsStr += F("}");
    jsStr += F("if (epdInd > 15 && epdInd < 22) {");
    jsStr += F("xhReq.onload = xhReq.onerror = function() {");
    jsStr += F("if (stInd == 0)");
    jsStr += F("return u_data(a, -1, 0, 100);");
    jsStr += F("if (stInd == 1)");
    jsStr += F("return u_done();");
    jsStr += F("};");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + 97) });");
    jsStr += F("}");
    jsStr += F("if (epdInd == 25 || epdInd == 37) {");
    jsStr += F("xhReq.onload = xhReq.onerror = function() {");
    jsStr += F("if (stInd == 0)");
    jsStr += F("return u_data(a, -2, 0, 100);");
    jsStr += F("if (stInd == 1)");
    jsStr += F("return u_done();");
    jsStr += F("}");
    jsStr += F(";");
    jsStr += F("if (epdInd > 25)");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + -26 + 65) });");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + 97) });");
    jsStr += F("} else {");
    jsStr += F("xhReq.onload = xhReq.onerror = function() {");
    jsStr += F("console.log('*************');");
    jsStr += F("console.log(stInd);");
    jsStr += F("console.log('*************');");
    jsStr += F("if (stInd == 0 && epdInd == 23)");
    jsStr += F("return u_data(a, 0, 0, 100);");
    jsStr += F("if (stInd == 0)");
    jsStr += F("return u_data(a, ((epdInd == 1) || (epdInd == 12)) ? -1 : 0, 0, 50);");
    jsStr += F("if (stInd == 1)");
    jsStr += F("return u_next();");
    jsStr += F("if (stInd == 2)");
    jsStr += F("return u_data(a, 3, 50, 50);");
    jsStr += F("if (stInd == 3)");
    jsStr += F("return u_done();");
    jsStr += F("};");
    jsStr += F("if (epdInd > 25)");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + -26 + 65) });");
    jsStr += F("return u_send('EPD', false, { ind: String.fromCharCode(epdInd + 97) });");
    jsStr += F("}");
    jsStr += F("}");
    return jsStr;
}